from pyecharts.charts import Line
from pyecharts import options as opts
import os
import numpy as np

import akshare as ak

# 示例数据
x_data = ["00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00"]
temperature = [25, 27, 28, 26, 29, 30, 32]  # 温度 (°C)
humidity = [45, 50, 55, 60, 58, 62, 65]    # 湿度 (%)
wind_speed = [3, 4, 2, 5, 3, 4, 3]         # 风速 (m/s)

percentile_90 = np.percentile(temperature, 90)
percentile_10 = np.percentile(temperature, 10)

symbol = input("Enter code: ")
pe_ttm = ak.stock_zh_valuation_baidu(symbol=symbol, indicator="市盈率(TTM)", period="全部")


line = (
    Line()
    .add_xaxis(x_data)
    
    # 添加第一个指标：温度
    .add_yaxis(
        series_name="温度",
        y_axis=temperature,
        color="#d14a61",  # 红色系
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=2),
        markline_opts=opts.MarkLineOpts(
            data=[
                opts.MarkLineItem(name="90% Percentile", y=percentile_90, linestyle_opts=opts.LineStyleOpts(color='green')),
                opts.MarkLineItem(name="10% Percentile", y=percentile_10, linestyle_opts=opts.LineStyleOpts(color='red'))
            ]
        )
    )
    
    # 添加第二个指标：湿度
    .add_yaxis(
        series_name="湿度",
        y_axis=humidity,
        color="#5793f3",  # 蓝色系
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=2),
    )
    
    # 添加第三个指标：风速
    .add_yaxis(
        series_name="风速",
        y_axis=wind_speed,
        color="#675bba",  # 紫色系
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=2),
    )
    
    # 全局配置
    .set_global_opts(
        title_opts=opts.TitleOpts(title="多指标趋势图"),
        tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
            name="综合指标",
            min_=0,
            max_=100,
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        legend_opts=opts.LegendOpts(pos_left="center", padding=5),
    )
)

# 渲染图表到HTML文件
line.render("multi_indicator_chart.html")
os.system("multi_indicator_chart.html")